#!/bin/bash
# 安装JDK

# 引入公共配置
source ./common.sh

echo "开始安装JDK..."

read -p "是否卸载系统自带jdk(y/n): " check_jdk
if [ "${check_jdk}" == "y" ];then
    rpm -qa|grep openjdk|xargs rpm -e --nodeps 2>/dev/null
    echo "可用的JDK版本："
    yum search jdk |grep devel.$(uname -i)|awk -F":" '{print $1}'
    read -p "请输入需要安装的jdk版本: " jdk
    yum -y install $jdk
    if [ $? -eq 0 ];then
        success_msg "$jdk安装完成"
    else
        error_exit "$jdk安装失败"
    fi
else
    echo "保留系统已有jdk，退出安装"
fi
